// components/thief/thief.js
Component({
  properties: {
    id: {
      type: Number,
      value: 0
    },
    avatar: {
      type: String,
      value: '/images/default-avatar.png'
    },
    name: {
      type: String,
      value: '小偷'
    },
    mood: {
      type: String,
      value: 'happy'
    },
    isSelected: {
      type: Boolean,
      value: false
    },
    specialAbility: {
      type: String,
      value: ''
    }
  },

  data: {
    isPressed: false
  },

  lifetimes: {
    attached() {
      // 组件实例进入页面节点树时执行
      console.log('Thief component attached with data:', this.data);
    }
  },
  
  observers: {
    'mood': function(mood) {
      // 将中文mood映射为CSS类名
      let moodClass = '';
      switch(mood) {
        case '兴奋':
          moodClass = 'xingfen';
          break;
        case '冷静':
          moodClass = 'lengjing';
          break;
        case '开心':
          moodClass = 'kaixin';
          break;
        case '愉快':
          moodClass = 'yukuai';
          break;
        default:
          moodClass = mood;
      }
      
      this.setData({
        moodClass: moodClass
      });
    }
  },

  methods: {
    onTap() {
      this.triggerEvent('select', {
        id: this.data.id,
        avatar: this.data.avatar,
        name: this.data.name,
        mood: this.data.mood,
        specialAbility: this.data.specialAbility
      });
    },

    onTouchStart() {
      this.setData({
        isPressed: true
      });
    },

    onTouchEnd() {
      this.setData({
        isPressed: false
      });
    }
  }
})

// 添加导出语句，确保组件可以被其他模块引用
module.exports = {
  Component: Component
};